package com.jiayu.wheel.controller;

import com.jiayu.wheel.dto.UserDto;
import com.jiayu.wheel.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/user")
public class UserAction {

    @Autowired
    private UserServiceImpl userService;

    @GetMapping("/q/{id}")
    public UserDto queryUserById(@PathVariable(value = "id") Integer id){
        return userService.getUserById(id);
    }

    @GetMapping("/q")
    public List<UserDto> queryUserByName(@PathParam("name") String name){
        return userService.getUserByName(name);
    }

    @PostMapping("/add")
    public void insertUser(@RequestBody UserDto userDto){
        userService.add(userDto);
    }

    @PostMapping("/delete")
    public void deleteById(@PathParam("id") int id){
        userService.deleteById(id);
    }

}
